package com.example.nophase.activity.staff;

import android.os.Bundle;
import android.view.MenuItem;
import android.widget.ListView;

import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;

import com.example.nophase.R;
import com.example.nophase.adapter.FinanceMsgAdapter;
import com.example.nophase.api.RequstCommonApi;
import com.example.nophase.base.BaseActivity;
import com.example.nophase.common.BaseCallBack;
import com.example.nophase.common.BaseResp;
import com.example.nophase.common.LoginManager;
import com.example.nophase.entity.FinanceMsgItem;
import com.example.nophase.entity.UserDTO;
import com.example.nophase.utils.HttpUtils;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import retrofit2.Call;
import retrofit2.Response;

public class LookOverFinanceMsgActivity extends BaseActivity {

    @BindView(R.id.applyfor_toolbar)
    Toolbar applyforToolbar;
    @BindView(R.id.finance_lv)
    ListView financeLv;
    private List<UserDTO> list;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_look_over_finance_msg);
        ButterKnife.bind(this);


        initData();

        initToolbar();

    }

    private void initData() {

        HttpUtils.getInstance().setAuthToken(LoginManager.getToken(this));
        Call<BaseResp<List<UserDTO>>> call = HttpUtils.getInstance().getApiService(RequstCommonApi.class).loadfinancial("ANDROID");
        call.enqueue(new BaseCallBack<BaseResp<List<UserDTO>>>() {
            @Override
            public void onSuccess(Response<BaseResp<List<UserDTO>>> response) throws Exception {
                List<UserDTO> list = response.body().getData();
                FinanceMsgAdapter adapter = new FinanceMsgAdapter(list, LookOverFinanceMsgActivity.this);
                financeLv.setAdapter(adapter);
                adapter.notifyDataSetChanged();
            }

            @Override
            public void onFailure(String message) {

            }
        });


    }


    private void initToolbar() {
        applyforToolbar.setTitle("");
        //设置导航图标要在setSupportActionBar方法之后
        setSupportActionBar(applyforToolbar);
        applyforToolbar.setNavigationIcon(R.drawable.ic_left_black_24dp);
        getSupportActionBar().setHomeButtonEnabled(true);


    }


    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {

            case android.R.id.home:
                this.finish();
                return true;

        }
        return super.onOptionsItemSelected(item);
    }
}
